package com.MRYIN.controller;

import com.MRYIN.mapper.KWMapper;
import com.MRYIN.pojo.KW;
import com.MRYIN.pojo.Payments;
import com.MRYIN.service.PaymentsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.*;

/**
 * @program: SHYC_03
 * @description: 款项图表统计
 * @author: Mr.YIN
 * @create: 2021-02-26 11:04
 **/
@Controller
@RequestMapping("/PaymentsEcharts")
public class KWEchartsController {

    @Autowired
    private PaymentsService paymentsService;

    @Autowired
    private KWMapper kwMapper;

    @RequestMapping("/Echarts/Bar")
    @ResponseBody
    public List<Map<String, Object>> kwPaymentsBar() {
        String[] KWType = new String[]{"合同款", "会签款", "预验款", "到货款","安装款","终验款","质保款"};
        List<Map<String, Object>> ls = new ArrayList<>();

        for (int i = 0; i < KWType.length; i++) {
            HashMap<String, Object> map = new HashMap<>();
            //查询所有该分类的款项
            List<Payments> i1 = paymentsService.queryAllPaymentsByPAY_NAME(KWType[i]);
            Double amountSum = 0.0; //定义应收款总数
            Double arrivedAmountSum = 0.0 ; //定义已收款总数
            for (Payments payments : i1) {
                Double pay_amount = payments.getPAY_AMOUNT();   //所有该分类款项的应收款
                Double pay_arrived_amount = payments.getPAY_ARRIVED_AMOUNT();   //所有该分类款项的已收款
                amountSum += pay_amount;
                arrivedAmountSum += pay_arrived_amount;
            }
            //查询所有该分类任务并且状态为0（未完成）的任务
            switch (KWType[i]) {
                case "合同款":
                    map.put("name", "合同款");
                    map.put("amountSum",amountSum);
                    map.put("arrivedAmountSum", arrivedAmountSum);
                    ls.add(map);
                    break;
                case "会签款":
                    map.put("name", "会签款");
                    map.put("amountSum",amountSum);
                    map.put("arrivedAmountSum", arrivedAmountSum);
                    ls.add(map);
                    break;
                case "预验款":
                    map.put("name", "预验款");
                    map.put("amountSum",amountSum);
                    map.put("arrivedAmountSum", arrivedAmountSum);
                    ls.add(map);
                    break;
                case "到货款":
                    map.put("name", "到货款");
                    map.put("amountSum",amountSum);
                    map.put("arrivedAmountSum", arrivedAmountSum);
                    ls.add(map);
                    break;
                case "安装款":
                    map.put("name", "安装款");
                    map.put("amountSum",amountSum);
                    map.put("arrivedAmountSum", arrivedAmountSum);
                    ls.add(map);
                    break;
                case "终验款":
                    map.put("name", "终验款");
                    map.put("amountSum",amountSum);
                    map.put("arrivedAmountSum", arrivedAmountSum);
                    ls.add(map);
                    break;
                case "质保款":
                    map.put("name", "质保款");
                    map.put("amountSum",amountSum);
                    map.put("arrivedAmountSum", arrivedAmountSum);
                    ls.add(map);
                    break;
            }
        }
            return ls;
    }

    @RequestMapping("/Echarts/fixLineBar")
    @ResponseBody
    public List<Map<String, Object>> kwPaymentsLineBar() {
        String[] KWType = new String[]{"合同款", "会签款", "预验款", "到货款","安装款","终验款","质保款"};
        List<Map<String, Object>> ls = new ArrayList<>();

        for (int i = 0; i < KWType.length; i++) {
            HashMap<String, Object> map = new HashMap<>();
            //查询所有该分类的款项
            List<Payments> i1 = paymentsService.queryAllPaymentsByPAY_NAME(KWType[i]);
            Double amountSum = 0.0; //定义应收款总数
            Double arrivedAmountSum = 0.0 ; //定义已收款总数
            for (Payments payments : i1) {
                Double pay_amount = payments.getPAY_AMOUNT();   //所有该分类款项的应收款
                Double pay_arrived_amount = payments.getPAY_ARRIVED_AMOUNT();   //所有该分类款项的已收款
                amountSum += pay_amount;
                arrivedAmountSum += pay_arrived_amount;
                //获取该分类的时间
            }
            //查询所有该分类任务并且状态为0（未完成）的任务
            switch (KWType[i]) {
                case "合同款":
                    map.put("name", "合同款");
                    map.put("amountSum",amountSum);
                    map.put("arrivedAmountSum", arrivedAmountSum);
                    ls.add(map);
                    break;
                case "会签款":
                    map.put("name", "会签款");
                    map.put("amountSum",amountSum);
                    map.put("arrivedAmountSum", arrivedAmountSum);
                    ls.add(map);
                    break;
                case "预验款":
                    map.put("name", "预验款");
                    map.put("amountSum",amountSum);
                    map.put("arrivedAmountSum", arrivedAmountSum);
                    ls.add(map);
                    break;
                case "到货款":
                    map.put("name", "到货款");
                    map.put("amountSum",amountSum);
                    map.put("arrivedAmountSum", arrivedAmountSum);
                    ls.add(map);
                    break;
                case "安装款":
                    map.put("name", "安装款");
                    map.put("amountSum",amountSum);
                    map.put("arrivedAmountSum", arrivedAmountSum);
                    ls.add(map);
                    break;
                case "终验款":
                    map.put("name", "终验款");
                    map.put("amountSum",amountSum);
                    map.put("arrivedAmountSum", arrivedAmountSum);
                    ls.add(map);
                    break;
                case "质保款":
                    map.put("name", "质保款");
                    map.put("amountSum",amountSum);
                    map.put("arrivedAmountSum", arrivedAmountSum);
                    ls.add(map);
                    break;
            }
        }
        return ls;
    }
}
